<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Building_controller extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->model('category/category');
        $this->load->model('building/building');
        $this->load->model('buildingimages/buildingimage');
        for ($i = BIET_THU_LAU_DAI; $i <= CONG_TRINH_CONG_CONG; $i++){
            $category_spot_list[$i] = $this->category->get_category_spots($i);
        }
        $this->data['category_spot_list'] = $category_spot_list;
    }
    
    public function index($cateID){
        $this->data['menu_item'] = $cateID;
        $path = "";
        switch ($cateID) {
            case 1:
                $path = "biet-thu-lau-dai";
                break;
            case 2:
                $path = "khach-san-nha-hang";
                break;
            case 3:
                $path = "noi-that-ngoai-that";
                break;
            case 4:
                $path = "quy-hoach";
                break;
            case 5:
                $path = "nha-ong-nha-pho";
                break;
            case 6:
                $path = "cong-trinh-cong-cong";
                break;
            default:
                break;
        }
        $building_list = $this->building->get_building_array_by_cat($cateID, 0, LIMIT);
        foreach ($building_list as &$building) {
            $building['building_image'] = $this->buildingimage->get_first_building_image($building['building_id']);
        }
        $this->data['path'] = $path;
        $this->data['building_list'] = $building_list;
        $this->load->view('building', $this->data);
    }
    
    public function building_detail($cateID = -1, $building_id = 0){
        $this->data['menu_item'] = $cateID;
        $building = $this->building->get_building($building_id);
        $building['building_images'] = $this->buildingimage->get_building_images($building_id, 0, LIMIT);
        $this->data['building'] = $building;
        $this->load->view('building_detail', $this->data);
    }
    
    public function get__more_building(){
        $offset = $this->input->post('offset');
        $cateID = $this->input->post('categoryID');
        $building_list = $this->building->get_building_array_by_cat($cateID, $offset, LIMIT);
        foreach ($building_list as &$building) {
            $building['building_image'] = $this->buildingimage->get_first_building_image($building['building_id']);
        }
        if (!$building_list){
            echo json_encode(array('status' => 'NO_DATA'));
        }else{
            $offset += count($building_list);
            echo json_encode(array('status' => 'SUCCESS', 'offset' => $offset, 'building_list' => $building_list));
        }
        die();
    }
    
    public function get_more_building_images(){
        $offset = $this->input->post('offset');
        $building_id = $this->input->post('buildingID');
        $image_list = $this->buildingimage->get_more_building_images($building_id, $offset, LIMIT);
        if (!$image_list){
            echo json_encode(array('status' => 'NO_DATA'));
        }else{
            $offset += count($image_list);
            echo json_encode(array('status' => 'SUCCESS', 'offset' => $offset, 'image_list' => $image_list));
        }
        die();
    }
}

/* End of file building.php */
/* Location: ./application/controllers/building.php */